     var screen=$(function(){

            function checkStockQuantity(rowId, tv, rawObject, cm, rdata){

                var classV='bg-success';
                     if(rawObject.onHandQty <=0)
                        classV='bg-danger';
                     else if(rawObject.onHandQty <=rawObject.reorderQty)
                                   classV='bg-warning';
                 return 'class="'+classV+'" title="The Qty on hand '+rawObject.onHandQty+' is less then Re-order Qty ('+ rawObject.reorderQty+')"';

            }

             var grid ;
             function initProductGrid(){
                grid=  $("#productGrid").jqGrid({
                             url: "search",
                             datatype: "json",
                             mtype: "GET",
                             colNames: ["Name","SKU", "Reg price","Manufacturer", "Stock Qty", "Description","Action"],
                             colModel: [
                                 { name: "name", width: 155 },
                                 { name: "sku", width: 90 },
                                 { name: "regPrice", width: 80, align: "center" ,formatter:'currency', formatoptions:currencyformatoptions},
                                 { name: "manufacturer", width: 80, align: "center" },
                                 { name: "onHandQty", width: 80, align: "center" ,cellattr:checkStockQuantity },
                                 { name: "description", width: 150, sortable: false },
                                 { name : 'productId', index:'productId', sortable:false,editable:false,key:true ,formatter:actionFormat,formatoptions: {icon: 'fa-pencil', link_class: 'add-link-class',model:'#productForm'}, unformat:actionUnFormat},
                             ],
                             pager: "#productGridPager",
                              postData: {
                                     query: function() { return $("#searchQuery").val(); }
                                 } ,
                             rowNum: 10,
                             rowList: [10, 20, 30],
                             sortname: "productId",
                             sortorder: "desc",
                             viewrecords: true,
                             gridview: true,
                             autoencode: true,
                             caption: "Products" ,
                             height:400,
                             autowidth : true,
                             jsonReader : {root:"products"},});

                initGridUI();
             }
             initProductGrid();

              $('#new-customer-form1').validator({custom:function($el){alert($el); return false;}}).on('submit', function (event) {

                       var button = $(event.relatedTarget) // Button that triggered the modal
                       var resetFlag = button.data('reset') // Extract info from data-* attributes
                       if (event.isDefaultPrevented()) {
                        // handle the invalid form...
                      } else {
                            event.preventDefault();

                            var options = {
                                   url:       'save' ,
                                   type:      'post' ,
                                   dataType:  'json' ,
                                   clearForm: true  ,
                                   resetForm: resetFlag  ,
                                   timeout:   9000  ,
                                    success:    function() {
                                                        if(!resetFlag){
                                                           grid.trigger("reloadGrid");
                                                           $('#customerForm').modal('hide');
                                                        }
                                                     }  ,
                                                      error:    function() {
                                                        $("#model-error-block").show();

                                                     }
                                                };

                                                $("#new-customer-form").ajaxSubmit(options) ;
                                                return false;
                      }
                });

                    			 $( "#search-item").button().click(function () {
                                     	grid.trigger("reloadGrid");
                        			});

                        			$('#productForm').modal({
                                            keyboard: false ,
                                            backdrop: false,
                                            show: false
                                    })

                                    $('#name').keyup(function(){

                                       $('#sku').val($(this).val().replace(/\s+/g, ''));
                                    });


//
//            $('#new-customer-form').find('input[name="name"]').change(function () {
//
//                            $.ajax({url: "getProductDetail", dataType: "json",data: {
//                                      "name": $("#name").val()
//                                  },success: function(result){
//                               alert(result);
//                               if(result.productId)
//                                   showErrors();
//                                else
//                                   clearErrors();
//
//
//                             }});
//
//            			});


    });

     function showProductDetail(index){

                 myApp.showPleaseWait();

                         $.ajax({url: "getProductDetail", dataType: "json",data: {
                                       "id": index
                             },success: function(productObj){
                                 myApp.hidePleaseWait();

                               if(productObj.productId)
                               {
                                      loadFormData(productObj);
                                      $('#model-title').text("Edit Item");

                               }
                                else{

                                }
                           }});

      }
